/*******************************************************************************
PROJECT: RESOLVE BURKINA STATISTICAL ANALYSIS
LOCATION: BURKINA FASO
AUTHORS: TRIANTAFYLLOS PLIAKAS (TP) AND LAURA HINSON (LH)	
PURPOSE: Run the analysis of RESOLVE BURKINA evaluation.

*******************************************************************************/

* SETUP ************************************************************************
*Use data
use "BF_analysis_data.dta", clear
log using "Endline_analysis.log",replace

***************************************************************************************************
*Check the association between individual predictors and having an intention to use contraception in the next three months
***************************************************************************************************
/*
Comments: 
Variables of interest: 	
city, school, grade, age, parental education, ethnicity, religion, wealth, 
sexual activity, sex-related beliefs, attitutes and norms
*/
#delimit ;						
local predictors	city school age grade religion2 ethn2 parental_educC eversex_2 currentsex_active whensex_active sexfreq_active currentFP_2 
					covid_effect covid_effect_B covid_anxiety covid_anxiety_B covid_mobility covid_mobility_B q5wealth
					providerbias providerbias_B
					confidence_get_fp confidence_get_fp_B confidence_use_fp confidence_use_fp_B confidence_getuse_fp 
					modern_method_use modern_method_use_B 
					modern_method_secretly modern_method_secretly_B modern_method_side_eff modern_method_side_eff_B 
					modern_method_infertility modern_method_infertil_B modern_method_best modern_method_best_B
					norm_endline_1_B norm_endline_2_B norm_endline_3_B norm_endline_17_B fp_norms;

local whynot_fp		whynot_fp_no_method whynot_fp_no_source whynot_fp_resp_opposed whynot_fp_part_opposed whynot_fp_other_opposed 
					whynot_fp_religious whynot_fp_god whynot_fp_lackaccess whynot_fp_not_avail_pref whynot_fp_not_avail whynot_fp_body 
					whynot_fp_inconven whynot_fp_sideeffect whynot_fp_cost whynot_fp_no_sex whynot_fp_infreq_sex whynot_fp_infertile 
					whynot_fp_bel_infertile whynot_fp_afraid whynot_fp_get_preg whynot_fp_pref_trad whynot_fp_no_boyfriend whynot_fp_no_need 
					whynot_fp_too_young whynot_fp_control whynot_fp_never_preg whynot_fp_my_choice whynot_fp_breastfeed whynot_fp_other 
					whynot_fp_dontknow whynot_fp_noanswer ; 

local whynot_fp_fut	whynot_fp_fut_no_method whynot_fp_fut_no_source whynot_fp_fut_resp_opposed
					whynot_fp_fut_part_opposed whynot_fp_fut_other_opposed whynot_fp_fut_religious whynot_fp_fut_god whynot_fp_fut_lackaccess 
					whynot_fp_fut_not_avail_pref whynot_fp_fut_not_avail whynot_fp_fut_body whynot_fp_fut_inconven whynot_fp_fut_sideeffect 
					whynot_fp_fut_cost whynot_fp_fut_no_sex whynot_fp_fut_infreq_sex whynot_fp_fut_infertile whynot_fp_fut_bel_infertile
					whynot_fp_fut_postpartum whynot_fp_fut_breastfeed whynot_fp_fut_notactive whynot_fp_fut_dnknowmethod whynot_fp_fut_sufficient 
					whynot_fp_fut_other whynot_fp_fut_dontknow whynot_fp_fut_noanswer ;
#delimit cr					
local sexrelated	currentsex whensex_active sexfreq_active

foreach var of local whynot_fp {
 replace  `var'=. if `var'==-1
}
foreach var of local whynot_fp_fut {
 replace  `var'=. if `var'==-1
}

foreach var of local predictors {
#delimit ;	
 if "`var'" == "providerbias" 				| 
	"`var'" == "providerbias_B" 			| 
	"`var'" == "confidence_get_fp" 			|	 
	"`var'" == "confidence_get_fp_B" 		| 
	"`var'" == "confidence_use_fp" 			| 
	"`var'" == "confidence_use_fp_B" 		| 
	"`var'" == "confidence_getuse_fp" 		| 
	"`var'" == "modern_method_use" 			| 
	"`var'" == "modern_method_use_B" 		| 
	"`var'" == "modern_method_secretly" 	| 
	"`var'" == "modern_method_secretly_B"	| 
	"`var'" == "modern_method_side_eff"		| 
	"`var'" == "modern_method_side_eff_B"	| 
	"`var'" == "modern_method_infertility"	| 
	"`var'" == "modern_method_infertil_B"	| 
	"`var'" == "modern_method_best"			| 
	"`var'" == "modern_method_best_B"		| 
	"`var'" == "norm_endline_1_B"			| 
	"`var'" == "norm_endline_2_B"			{ ;
  local ifstatement="if `var'!=99" ;
 } ;
 else if 	"`var'" == "currentsex_active"	|
			"`var'" == "sexfreq_active" { ;
  local ifstatement="if `var'!=98" ;
 } ;
 else if 	"`var'" == "norm_endline_3_B"	|
			"`var'" == "norm_endline_17_B"  |
			"`var'" == "fp_norms" { ;
  local ifstatement="if `var'!=99 & `var'!=-1" ;
 } ;
 else { ;
  local ifstatement="" ;
 } ;
#delimit cr 
 eststo m_`var', title("`: var lab `var''")	: xtgee intention3months_b_use i.`var' `ifstatement' , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
 *Wald test 
 testparm i.`var' 
}

#delimit ;

tabout `predictors' 	using "docs/Individual_predictors_freq.rtf" , 
						cell(freq col) f(0 1)
						clab(n %) mi
						ptotal(none)
						oneway
						replace   ; 
tabout `whynot_fp' 		using "docs/Why_not_FP_freq.rtf" , 
						cell(freq col) f(0 1)
						clab(n %) 
						ptotal(none)
						oneway
						replace   ; 
tabout `whynot_fp_fut'	using "docs/Why_not_FP_freq.rtf" , 
						cell(freq col) f(0 1)
						clab(n %) 
						ptotal(none)
						oneway
						append   ; 						
						
						
estout 	m_city	 					using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									title("Predictors of having an intention to use contraception in the next three months")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.city "Ouaga", label("1.00") )
									drop(1.city _cons) 
									stats(p, fmt(3) ) 
									label 
									eform 
									replace;
estout 	m_school	 				using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.school "Private", label("1.00") )
									drop(1.school _cons) 
									stats(p, fmt(3) ) 
									label 
									eform 
									append;	
estout 	m_age	 					using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(15.age "14", label("1.00") )
									drop(14.age _cons) 
									stats(p, fmt(3) ) 
									label 
									eform 
									append;	
estout 	m_grade		 				using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.grade "4eme", label("1.00") )
									drop(1.grade _cons) 
									stats(p, fmt(3) ) 
									label 
									eform 
									append;			
estout 	m_parental_educC 			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.parental_educC "None/illiterate", label("1.00") )
									drop(1.parental_educC _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;			
estout 	m_religion2		 			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.religion2 "Muslim", label("1.00") )
									drop(1.religion2 _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;			
estout 	m_ethn2			 			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.ethn2 "Mossi", label("1.00") )
									drop(1.ethn2 _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;		
estout 	m_eversex_2		 			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.eversex_2 "Has never had sex", label("1.00") )
									drop(0.eversex_2 _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;		
estout 	m_currentFP_2	 			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.currentFP_2 "No", label("1.00") )
									drop(0.currentFP_2 _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;	
estout 	m_covid_effect 				using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.covid_effect "Not at all", label("1.00") )
									drop(1.covid_effect _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;		
estout 	m_covid_effect_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.covid_effect_B "Not at all", label("1.00") )
									drop(0.covid_effect_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;	
estout 	m_covid_anxiety 			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.covid_anxiety "Not at all", label("1.00") )
									drop(1.covid_anxiety _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;		
estout 	m_covid_anxiety_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.covid_anxiety_B "Not at all", label("1.00") )
									drop(0.covid_anxiety_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;		
estout 	m_covid_mobility 			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.covid_mobility "Not at all", label("1.00") )
									drop(1.covid_mobility _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;			
estout 	m_covid_mobility_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.covid_mobility_B "Not at all", label("1.00") )
									drop(0.covid_mobility_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;				
estout 	m_q5wealth					using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.q5wealth "First quintile (Less wealthy)", label("1.00") )
									drop(1.q5wealth _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;				
estout 	m_providerbias_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.providerbias_B "Disagree", label("1.00") )
									drop(0.providerbias_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;								
estout 	m_confidence_get_fp_B		using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.confidence_get_fp_B "Disagree", label("1.00") )
									drop(0.confidence_get_fp_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;								
estout 	m_confidence_use_fp_B		using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.confidence_use_fp_B "Disagree", label("1.00") )
									drop(0.confidence_use_fp_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;										
estout 	m_confidence_getuse_fp		using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.confidence_getuse_fp "Disagree", label("1.00") )
									drop(0.confidence_getuse_fp _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;										
estout 	m_modern_method_use_B		using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.modern_method_use_B "Disagree", label("1.00") )
									drop(0.modern_method_use_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;										
estout 	m_modern_method_secretly_B	using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.modern_method_secretly_B "Disagree", label("1.00") )
									drop(0.modern_method_secretly_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;	 								
estout 	m_modern_method_side_eff_B	using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.modern_method_side_eff_B "Disagree", label("1.00") )
									drop(0.modern_method_side_eff_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;								
estout 	m_modern_method_infertil_B	using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.modern_method_infertil_B "Disagree", label("1.00") )
									drop(0.modern_method_infertil_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;									
estout 	m_modern_method_best_B		using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.modern_method_best_B "Disagree", label("1.00") )
									drop(0.modern_method_best_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;
estout 	m_norm_endline_1_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.norm_endline_1_B "Disagree", label("1.00") )
									drop(0.norm_endline_1_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;
estout 	m_norm_endline_2_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.norm_endline_2_B "Disagree", label("1.00") )
									drop(0.norm_endline_2_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;
estout 	m_norm_endline_3_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.norm_endline_3_B "Disagree", label("1.00") )
									drop(0.norm_endline_3_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;
estout 	m_norm_endline_17_B			using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.norm_endline_17_B "Disagree", label("1.00") )
									drop(0.norm_endline_17_B _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;
									
									
estout 	m_fp_norms					using "docs\GEE_models_individual_RFs_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(1.fp_norms "Disagree", label("1.00") )
									drop(0.fp_norms _cons) 
									stats(p, fmt(3) ) 
									label
									eform 
									append;		
									
									
#delimit cr
***************************************************************************************************
*##################### 					MAIN ANALYSES						 #####################*
***************************************************************************************************

***************************************************************************************************
*Main analysis looking at the impact of Resolve on having an intention to use contraception in the next three months
***************************************************************************************************
eststo m_unadj, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base  , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj	 					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months (n=2,072)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									replace;
estout 	m_adj1	 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2	 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3	 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj	 					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months (n=2,072) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1	 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2	 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3	 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
#delimit cr									
									

***************************************************************************************************
*Main analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- among EVER sexually active girls only
***************************************************************************************************
eststo m_unadj_sex, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if eversex_2==1 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_sex, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if eversex_2==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_sex, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if eversex_2==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_sex, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if eversex_2==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_sex					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - among ever sexually active girls (n=391)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_sex 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_sex 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_sex 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_sex					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - among ever sexually active girls (n=391) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_sex 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_sex 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_sex 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr										

***************************************************************************************************
*Main analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- among the girls that had never had sex
***************************************************************************************************
eststo m_unadj_nosex, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if eversex_2==0 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_nosex, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if eversex_2==0, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_nosex, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if eversex_2==0, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_nosex, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if eversex_2==0, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_nosex				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - among the girls that had never had sex (n=1,681)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_nosex 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_nosex 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_nosex				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_nosex				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - among the girls that had never had sex (n=1,681) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_nosex 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_nosex 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_nosex 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr											


***************************************************************************************************
*##################### 			SENSITIVITY/STRATIFIED ANALYSES				 #####################*
***************************************************************************************************

***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by been ever sexually active or not 
***************************************************************************************************
recode eversex_2 (0=2 "Never had sex") (1=1 "Had sex"), gen(eversex_b)
xtgee intention3months_b_use i.eversex_b##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
if `estimates4' <0.001 {
 local eversex_b = "p{sub:interaction}<0.001" 
}
else {
 local eversex_b = "p{sub:interaction}=`:di %4.3f `estimates4''" 
}

xtgee intention3months_b_use i.eversex_b##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins eversex_b#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.1 "`eversex_b'", size(small) place(e))
				name(eversex_b_arm,replace)
				saving("graphs/eversex_b_arm.gph",replace);
graph export "graphs\eversex_b_arm.pdf", as(pdf) replace ;
graph export "graphs\eversex_b_arm.png", as(png) replace ;
#delimit cr

***************************************************************************************************
*Analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- private school
***************************************************************************************************
eststo m_unadj_private, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if school==1 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_private, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if school==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_private, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if school==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_private, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if school==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_private				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - Private schools (n=1,528)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_private 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_private 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_private				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_private				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - Private schools (n=1,528) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_private 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_private 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_private 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr		


***************************************************************************************************
*Analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- private versus public school
***************************************************************************************************
eststo m_unadj_public, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if school==2 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_public, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if school==2, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_public, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if school==2, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_public, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if school==2, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_public				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - Public schools (n=544)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_public 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_public 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_public				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_public				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - Public schools (n=544) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_public 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_public 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_public 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr	

***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on intention to use contraception in the next three months 
*by type of school 
***************************************************************************************************

xtgee intention3months_b_use i.school##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_school = "p{sub:interaction}=`:di %4.3f `estimates4''" 
if `estimates4' <0.001 {
 local p_school = "p{sub:interaction}<0.001" 
}
else {
 local p_school = "p{sub:interaction}=`:di %4.3f `estimates4''" 
}
xtgee intention3months_b_use i.school##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins school#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_school'", size(small) place(e))
				name(school_arm,replace)
				saving("graphs/school_arm.gph",replace);
graph export "graphs\school_arm_14july2022.pdf", as(pdf) replace ;
graph export "graphs\school_arm_14july2022.png", as(png) replace ;
#delimit cr

	
***************************************************************************************************
*Analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- among 4eme
***************************************************************************************************
eststo m_unadj_4eme, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if grade==1 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_4eme, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if grade==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_4eme, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if grade==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_4eme, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.q5wealth if grade==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_4eme				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - 4eme (n=948)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_4eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_4eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_4eme					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_4eme				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - 4eme (n=948) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_4eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_4eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_4eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr	

***************************************************************************************************
*Analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- among 3eme
***************************************************************************************************
eststo m_unadj_3eme, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if grade==2 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_3eme, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if grade==2, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_3eme, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if grade==2, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_3eme, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.q5wealth if grade==2, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_3eme				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - 3eme (n=1,124)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_3eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_3eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_3eme					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_3eme				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - 3eme (n=1,124) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_3eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_3eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_3eme 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr	
***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by grade
***************************************************************************************************

xtgee intention3months_b_use i.grade##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.q5wealth, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_grade = "p{sub:interaction}=`:di %4.3f `estimates4''" 

xtgee intention3months_b_use i.grade##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.q5wealth, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins grade#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_grade'", size(small) place(e))
				name(grade_arm,replace)
				saving("graphs/grade_arm.gph",replace);
graph export "graphs\grade_arm_14july2022.pdf", as(pdf) replace ;
graph export "graphs\grade_arm_14july2022.png", as(png) replace ;
#delimit cr
	
***************************************************************************************************
/*
Analysis looking at the impact of Resolve on intention to use contraception in the next three months 
among girls who went to a (re)solve health facility 
-Restrict analysis to girls who went to a (re)solve health facility 
-Restrict analysis to girls who did not go to a (re)solve health facility 
*/
***************************************************************************************************
*Generate variable for girls who went to a (re)solve health facility
gen facilityvisitno = 0
replace facilityvisitno=1 if ever_visit_hf_pub_men==1 | ever_visit_hf_contra==1
replace facilityvisitno=0 if facilityvisitno==1 & arm==1

*Generate variable for girls who did not go to a (re)solve health facility
gen facilityvisityes = 0 
replace facilityvisityes=1 if facilityvisitno==1 | arm==1

lab values facilityvisityes noyes
lab values facilityvisitno noyes
	
***************************************************************************************************
*Analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- girls who went to a (re)solve health facility
***************************************************************************************************
eststo m_unadj_yes, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if facilityvisityes==1 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_yes, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if facilityvisityes==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_yes, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if facilityvisityes==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_yes, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if facilityvisityes==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_yes					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - girls who went to a (re)solve health facility (n=1,379)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_yes 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_yes 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_yes					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_yes					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - girls who went to a (re)solve health facility (n=1,379) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_yes 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_yes 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_yes 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr	

***************************************************************************************************
*Analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- girls who did not go to a (re)solve health facility
***************************************************************************************************
eststo m_unadj_no, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if facilityvisitno==0 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_no, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if facilityvisitno==0, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_no, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if facilityvisitno==0, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_no, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.grade i.city i.q5wealth if facilityvisitno==0, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_no					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - girls who did not go to a (re)solve health facility (n=1,747)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_no 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_no 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_no					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_no					using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - girls who did not go to a (re)solve health facility (n=1,747) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_no 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_no 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_no 					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr	

	
***************************************************************************************************
/*
Analysis looking at the impact of Resolve on intention to use contraception in the next three months 
among girls who had an intention to go to clinic (but didn’t follow through because of COVID, time constraints, etc). 
I think the point here is that there were a handful of girls who really wanted to go but didn’t for these legitimate reasons, 
they are like the “near misses” – could have been in the “gone to facility” group.
-Restrict analysis to girls who were "near misses" 
*/
***************************************************************************************************
* Generate var to classify legitimate reasons
#delimit ;
recode whynot_visit_hf_contra 	(5/12 = 1 "Yes")
								(else = 0 "No"), gen(nearmiss) ;
#delimit cr

*Generate variable for girls who were 'near misses'
gen nearmiss_analysis = 0
replace nearmiss_analysis=1 if nearmiss==1 | arm==1

lab values nearmiss_analysis noyes
lab values nearmiss noyes

***************************************************************************************************
*Analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*- girls considered as "near misses"
***************************************************************************************************
eststo m_unadj_near, title("Unadjusted model")	: xtgee intention3months_b_use i.arm i.intention3months_b_base if nearmiss_analysis==1 , family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj1_near, title("Adjusted model 1")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age if nearmiss_analysis==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj2_near, title("Adjusted model 2")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 if nearmiss_analysis==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
eststo m_adj3_near, title("Adjusted model 3")	: xtgee intention3months_b_use i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.grade i.city i.q5wealth if nearmiss_analysis==1, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform

#delimit ;
estout 	m_unadj_near				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - girls considered as ''near misses'' (n=1,419)")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base _cons) 
									label 
									eform 
									append;
estout 	m_adj1_near 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm 0.intention3months_b_base 1.intention3months_b_base 14.age 15.age 16.age 17.age 18.age 19.age _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_near 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B 
											0.currentFP_2 1.currentFP_2 
											_cons) 
									label 
									eform 
									append;	
estout 	m_adj3_near					using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm 
											0.intention3months_b_base 1.intention3months_b_base 
											14.age 15.age 16.age 17.age 18.age 19.age 
											0.covid_mobility_B 1.covid_mobility_B
											0.currentFP_2 1.currentFP_2 
											1.city 2.city
											1.grade 2.grade
											1.q5wealth 2.q5wealth 3.q5wealth 4.q5wealth 5.q5wealth
											_cons) 
									label 
									eform 
									append;	
estout 	m_unadj_near				using "docs\GEE_models_main_analysis.rtf",
									title("Impact of Resolve on having an intention to use contraception in the next three months - girls considered as ''near misses'' (n=1,419) - All coefficients")
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;
estout 	m_adj1_near 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj2_near 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(1.arm _cons) 
									label 
									eform 
									append;	
estout 	m_adj3_near 				using "docs\GEE_models_main_analysis.rtf",
									cells(b(fmt(2) label("OR")) &  ci(par(`"("'`"-"'`")"') label("95% CI")) ) 
									refcat(2.arm "Control", label("1.00") )
									drop(	1.arm _cons) 
									label 
									eform 
									append;
#delimit cr	


***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by confidence in ability to use and get a contraceptive method 
***************************************************************************************************

xtgee intention3months_b_use i.confidence_getuse_fp##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if confidence_getuse_fp!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_contra = "p{sub:interaction}=`:di %4.3f `estimates4''" 

xtgee intention3months_b_use i.confidence_getuse_fp##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if confidence_getuse_fp!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins confidence_getuse_fp#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_contra'", size(small) place(e))
				name(contra_arm,replace)
				saving("graphs/contra_arm.gph",replace);
graph export "graphs\contra_arm.pdf", as(pdf) replace ;
graph export "graphs\contra_arm.png", as(png) replace ;
#delimit cr


***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by modern contraception can be used by girls 
***************************************************************************************************

xtgee intention3months_b_use i.modern_method_use_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_use_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_modern = "p{sub:interaction}=`:di %4.3f `estimates4''" 

xtgee intention3months_b_use i.modern_method_use_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_use_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins modern_method_use_B#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_modern'", size(small) place(e))
				name(modern_arm,replace)
				saving("graphs/modern_arm.gph",replace);
graph export "graphs\modern_arm.pdf", as(pdf) replace ;
graph export "graphs\modern_arm.png", as(png) replace ;
#delimit cr


***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by feeling confident to use contra secretly
***************************************************************************************************

xtgee intention3months_b_use i.modern_method_secretly_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_secretly_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_secret = "p{sub:interaction}=`:di %4.3f `estimates4''" 

xtgee intention3months_b_use i.modern_method_secretly_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_secretly_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins modern_method_secretly_B#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_secret'", size(small) place(e))
				name(secret_arm,replace)
				saving("graphs/secret_arm.gph",replace);
graph export "graphs\secret_arm.pdf", as(pdf) replace ;
graph export "graphs\secret_arm.png", as(png) replace ;
#delimit cr


***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by contra having negative side effects
***************************************************************************************************

xtgee intention3months_b_use i.modern_method_side_eff_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_side_eff_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_side = "p{sub:interaction}=`:di %4.3f `estimates4''" 

xtgee intention3months_b_use i.modern_method_side_eff_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_side_eff_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins modern_method_side_eff_B#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_side'", size(small) place(e))
				name(side_arm,replace)
				saving("graphs/side_arm.gph",replace);
graph export "graphs\side_arm.pdf", as(pdf) replace ;
graph export "graphs\side_arm.png", as(png) replace ;
#delimit cr

***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by contra causing infertility
***************************************************************************************************

xtgee intention3months_b_use i.modern_method_infertil_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_infertil_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_infertil = "p{sub:interaction}=`:di %4.3f `estimates4''" 

xtgee intention3months_b_use i.modern_method_infertil_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_infertil_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins modern_method_infertil_B#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_infertil'", size(small) place(e))
				name(infertil_arm,replace)
				saving("graphs/infertil_arm.gph",replace);
graph export "graphs\infertil_arm.pdf", as(pdf) replace ;
graph export "graphs\infertil_arm.png", as(png) replace ;
#delimit cr

***************************************************************************************************
*Interaction analysis looking at the impact of Resolve on having an intention to use contraception in the next three months 
*by contra is best option
***************************************************************************************************

xtgee intention3months_b_use i.modern_method_best_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_best_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
return list 
ereturn list 

matrix stats		= r(table) 
foreach i of numlist 1/9{ 
 local estimates`i' = stats[`i',8]
} 
local p_best = "p{sub:interaction}=`:di %4.3f `estimates4''" 

xtgee intention3months_b_use i.modern_method_best_B##i.arm i.intention3months_b_base i.age i.covid_mobility_B i.currentFP_2 i.city i.grade i.q5wealth if modern_method_best_B!=99, family(binomial) link(logit) corr(exch) i(cluster) vce(robust) eform
margins modern_method_best_B#arm

#delimit ;
mplotoffset, 	xdimension(arm) recast(scatter) scheme(s2mono) 
				title("")
				ytitle(	"{bf:Probability to have an intention to}"
						"{bf:use contraception in next three months}", size(medsmall))
				offset(0.2)
				ylabel(0(0.1)0.6, nogrid labsize(small)) 
				yscale(noextend)
				xtitle("")
				xlabel(1 "Control schools" 2 "Intervention schools",labsize(small)) 
				xscale(r(0.5(1)2.5)) 
				graphregion(color(white))
				plotregion(color(white))
				legend(region(lc(white)) size(small) rows(2) ring(0) position(1))
				text( 0.5 2.25 "`p_best'", size(small) place(e))
				name(best_arm,replace)
				saving("graphs/best_arm.gph",replace);
graph export "graphs\best_arm.pdf", as(pdf) replace ;
graph export "graphs\best_arm.png", as(png) replace ;
#delimit cr

***************************************************************************************************
*Added during manuscript revision
*Run permutation test and Use the Wilcoxon rank-sum test to test for a difference in the distribution of y between intervention and control schools
***************************************************************************************************
*Use data
use "BF_data_clusters.dta", clear

*Baseline data
preserve
keep if round==1
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum intention3m, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum conf_getuse_fp, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum infertility, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum bestmethod, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum providerbias, by(arm)
restore
   
*Endline data
preserve
keep if round==3
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum intention3m, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum conf_getuse_fp, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum infertility, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum bestmethod, by(arm)
permute arm rsum=r(sum_obs), reps(1000) nowarning nodots :  ranksum providerbias, by(arm)
restore
log close
